﻿@using System.Globalization
@using Lari.Configuration
@model Lari.Services.ViewModel.SpecializationListModel
@{
    Layout = "~/Views/Shared/DialogLayout.cshtml";
    string buttonText;
}
<div style="float: right">
    Departemnt:&nbsp;<strong> @Model.DepartmentName</strong>
</div>
@if (Model.Specializations != null && Model.Specializations.Count > 0 && Model.ActionMode == EditingMode.View)
{
    <div style="float: left">
        <a href="#top" class="moduleLink">Top</a>&nbsp;&nbsp;&nbsp;<a class="moduleLink"
            href="#bottom">Bottom</a>
    </div>
}
<div class="spacer">
</div>
<div class="clear">
</div>
@*display specilization in view mode*@
@if (Model.Specializations != null && Model.Specializations.Count > 0)
{
    <div style="height: 350px; overflow: auto">
        <table>
            @for (int i = 0; i < Model.Specializations.Count; i++)
            {
                if (i == 0)
                {
                <tr><td><a id="top" /></td></tr>
                }
                <tr>
                    <td style="border-bottom: 0px solid #DADADA; border-top: 1px solid #DADADA; width: 90%;
                        padding-top: 3px; padding-bottom: 3px">
                        <label>@Model.Specializations[i].Name</label>
                    </td>
                    <td style="border-bottom: 0px solid #DADADA; border-top: 1px solid #DADADA; width: 10%;
                                                                    padding-top: 3px; padding-bottom: 3px">
                        @using (Ajax.BeginForm(ActionConst.Masters.Common.SpecializationModify, new { id = Model.Specializations[i].ID }, new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "popUpDialog" }, new { @id = "FormM" + i.ToString(CultureInfo.InvariantCulture) }))
                        {
                            <input type="submit" value="Modify" class="buttonModify"/>
                        }
                    </td>
                    <td style="border-bottom: 0px solid #DADADA; border-top: 1px solid #DADADA; width: 10%;
                        padding-top: 3px; padding-bottom: 3px">
                        @using (Ajax.BeginForm(ActionConst.Masters.Common.SpecializationDelete, new { id = Model.Specializations[i].ID }, new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "popUpDialog" }, new { @id = "FormD" + i.ToString(CultureInfo.InvariantCulture) }))
                        {
                            <input type="submit" value="Delete" class="buttonDelete"/>
                        }
                    </td>
                </tr>

                        if (i == Model.Specializations.Count - 1)
                        {
                <tr><td><a id="bottom" /></td></tr>
                        }
            }
        </table>
    </div>
  
}
@if (Model.ActionMode == EditingMode.View)
{
    buttonText = "Add New Specialization";
    using (Ajax.BeginForm(ActionConst.Masters.Common.SpecializationAdd, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "popUpDialog" }))
    {
    @Html.AntiForgeryToken("New Spec") 
        
    <p style="float: right">
        @Html.HiddenFor(m => m.DepartmentId)
        @Html.HiddenFor(m => m.DepartmentName)
        <input type="submit" value="@buttonText" id="butnAdd" />
    </p>
    }
}

@*when insert clicked*@
@if (Model.ActionMode == EditingMode.Insert)
{
    buttonText = "Save New Specialization";
    using (Ajax.BeginForm(ActionConst.Masters.Common.SpecializationAddSave, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "popUpDialog" }))
    {
         
    @Html.AntiForgeryToken("spc save")
    <div>
        <label class="required">
            Specialization</label>
    </div>
    <div>
        @Html.TextBoxFor(m => m.SpecializationName)
        @Html.ValidationMessageFor(m => m.SpecializationName)
    </div>
    <div class="spacer">
    </div>
    <div class="clear">
    </div>
        
    <p style="float: right">
        @Html.HiddenFor(m => m.DepartmentId)
        @Html.HiddenFor(m => m.DepartmentName)
        <input type="submit" value="@buttonText" id="butnAdd" />
    </p>
    }

    using (Ajax.BeginForm(ActionConst.Masters.Common.Specialization, new { id = Model.DepartmentId }, new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "popUpDialog" }))
    {
    <p style="float: left">
        @Html.HiddenFor(m => m.DepartmentId)
        @Html.HiddenFor(m => m.DepartmentName)
        <input type="submit" value="Cancel" id="btcCancel" />
    </p>
    }
}

@*when modify is clicked*@
@if (Model.ActionMode == EditingMode.Edit)
{
    buttonText = "Update Specialization";
    using (Ajax.BeginForm(ActionConst.Masters.Common.SpecializationModifySave, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "popUpDialog" }))
    {
         
    @Html.AntiForgeryToken("spc modify")
    <div>
        <label class="required">
            Specialization</label>&nbsp;<label style="font-size: 11px">(@Model.OldSpecializationName)</label>
    </div>
    <div>
        @Html.TextBoxFor(m => m.SpecializationName)
        @Html.ValidationMessageFor(m => m.SpecializationName)
    </div>
    <div class="spacer">
    </div>
    <div class="clear">
    </div>
        
    <p style="float: right">
        @Html.HiddenFor(m => m.DepartmentId)
        @Html.HiddenFor(m => m.SpecializationsId)
        @Html.HiddenFor(m => m.DepartmentName)
        @Html.HiddenFor(m => m.OldSpecializationName)
        <input type="submit" value="@buttonText" id="butnAdd" />
    </p>
    }

    using (Ajax.BeginForm(ActionConst.Masters.Common.Specialization, new { id = Model.DepartmentId }, new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "popUpDialog" }))
    {
    <p style="float: left">
        @Html.HiddenFor(m => m.DepartmentId)
        @Html.HiddenFor(m => m.DepartmentName)
        <input type="submit" value="Cancel" id="btcCancel" />
    </p>
    }
}

<script type="text/javascript">
    var deleteLinkUrl;
    
    $(document).ready(function () {
        $("#butnAdd").button();
        $("#btcCancel").button();
        $(".buttonModify").button();
        $(".buttonDelete").button();

    });
</script>
